<!--  厂家-维修结算 -->
<template>
	<ListLayout>
		<!-- 维修情况 -->
		<HandleMaintenanceCard ref="HandleMaintenanceCard" :hideenSettlement="false"></HandleMaintenanceCard>
		<!-- 维修信息 -->
		<RepairHandleCard ref="RepairHandleCard"></RepairHandleCard>
		<!-- 发票信息 -->
		<InvoiceHandleCard ref="InvoiceHandleCard"></InvoiceHandleCard>

		<template #footer>
			<HButtonGroup @leftClick="onCancel" @rightClick="onSubmit">
				<template #left>
					取消
				</template>
				<template #right>
					确认维修结算
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>
</template>

<script>
	import ListLayout from '@/components/layout/listLayout.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'

	import HandleMaintenanceCard from '@/components/card/sendRepair/factory/info/handleMaintenance.vue'
	import RepairHandleCard from '@/components/card/sendRepair/factory/info/handleRepair.vue'
	import InvoiceHandleCard from '@/components/card/sendRepair/factory/info/handleInvoice.vue'
	import ReapirApi from '@/apis/repair.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	import { attachmentFormatter } from '@/common/submitFormatter.js'
	export default {
		components: {
			ListLayout,
			HandleMaintenanceCard,
			RepairHandleCard,
			InvoiceHandleCard,
			HButtonGroup,
		},
		data() {
			return {
				routerParams: {
					id: ''
				}
			}
		},
		onLoad(query) {
			console.log('onLoad', query);
			const {
				id
			} = query
			this.$set(this.routerParams, 'id', id)
		},
		methods: {
			onCancel() {
				wx.navigateBack()
			},
			async onSubmit() {
				let mantenanceData = this.$refs.HandleMaintenanceCard.$data.formData
				let { repairList } = this.$refs.RepairHandleCard.$data
				let invoiceData = this.$refs.InvoiceHandleCard.$data.formData


				let params = {
					// 送修id
					repairId: this.routerParams.id,
					// 设备数据状态
					deviceData: mantenanceData.deviceData,
					// 是否有发票（0.否，1.是）
					invoiceFlag: invoiceData.isVoice ? 1 : 0,
					// 发票类型
					invoiceType: invoiceData.invoiceType,
					// 发票号
					invoiceNum: invoiceData.invoiceNum,
					// 发票附件
					invoiceEnclosure: attachmentFormatter(invoiceData.invoiceAttachment),
					// 附件
					enclosure: attachmentFormatter(mantenanceData.enclosure),
					// 维修项目详情 [{"name":"维修项测试","num":"5"},{"name":"维修项测试2","num":"20"}]		
					maintenanceItem: JSON.stringify(repairList),
					// 设备状态外观
					deviceState: mantenanceData.deviceState,
				}
				console.log(params);
				await ReapirApi.factory.confirmSettlement(params)

				wx.showToast({
					title: '提交成功!',
					icon: 'success',
					complete() {
						wx.redirectTo({
							url: SendRepairRouterConfig.Factory.Index
						})
					}
				})


			}

		},

	}
</script>

<style>
</style>
